package TestDemo1;

public class TestDemo {
    public static int compare (String version1, String version2) {
        // write code here
        //version1的指针
        int i1 = 0;
        int last1 = 0;
        //version2的指针
        int i2 = 0;
        int last2 = 0;
        int num1 = 0;
        int num2 = 0;
        while (i1 != version1.length()-1 && i2 != version2.length()-1 ) {

            while (version1.charAt(i1) != '.') {
                i1++;
            }
            num1 = Integer.parseInt(version1.substring(last1, i1));
            last1 = i1 + 1;
            i1++;
            while (version2.charAt(i2) != '.' ) {
                i2++;
            }
            num2 = Integer.parseInt(version2.substring(last2, i2));
            last2 = i2 + 1;
            i2++;
            if (num1 > num2) {
                return 1;
            }
            if (num2 > num1) {
                return -1;
            }

        }
        num1 = Integer.parseInt(version1.substring(last1, i1+1));
        num2 = Integer.parseInt(version2.substring(last2, i2+1));
        if (num1 > num2) {
            return 1;
        }
        if (num2 > num1) {
            return -1;
        }
        return 0;
    }
    public static void main(String[] args) {
        int ret=compare("1.1","1.2");
        System.out.println(ret);


    }
}
